package com.myh.cc.coom.singer.adapter

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.myh.cc.base.BaseApplication.Companion.context
import com.myh.cc.coom.singer.bean.SingerBean
import com.myh.cc.databinding.ItemSingerRvBinding
import com.myh.cc.widget.OnItemClickListener

/**
 * des    ：
 * create    ：  mayahao.
 * date   ：  2018/1/14.   ：
 */
class SingerAdapter(bean: SingerBean) : RecyclerView.Adapter<SingerAdapter.VH>(){

    val bean = bean

    var mListener: OnItemClickListener? = null

    override fun onBindViewHolder(holder: VH, position: Int) {

        val  list = bean.data.list

        val picUrl = "https://y.gtimg.cn/music/photo_new/T001R150x150M000"+list[position].Fsinger_mid+".jpg?max_age=2592000"

        Glide.with(context).load(picUrl).into(holder.binding.itemSingerIvImg)

        holder.binding.itemSingerTvName.text = list[position].Fsinger_name

        holder.binding.singerRaleRoot.setOnClickListener { view ->
            mListener?.onClick(view,position)
        }

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        return VH.create(LayoutInflater.from(parent.context),parent)
    }

    override fun getItemCount(): Int {
        return bean.data.list.size
    }





    class VH(binding: ItemSingerRvBinding): RecyclerView.ViewHolder(binding.root){

        val  binding = binding

        companion object {

            fun  create(inflater: LayoutInflater,parent: ViewGroup): SingerAdapter.VH{

                val binding = ItemSingerRvBinding.inflate(inflater,parent,false)
                return SingerAdapter.VH(binding)
            }



        }
    }
}